package kit.edu.lego.gruppe3.levels.line;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import lejos.nxt.LightSensor;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.*;
import kit.edu.lego.gruppe3.sensors.Scanner;

public class LineObstacle implements Behavior
{

	private DifferentialPilot robot = ComponentsRepository.getInstance().getRobotPilot();
	LightSensor lightSensor = ComponentsRepository.getInstance().getLightSensor();
	UltrasonicSensor sonicSensor = ComponentsRepository.getInstance().getSonicSensor();
	
	@Override
	public void action()
	{	

		robot.travel(10);
		if(sonicSensor.getDistance() > 20) return;

		Scanner.getRangeAt(90, true);
		ComponentsRepository.evadeObstacle = true;
		robot.rotate(+100);
		robot.travel(5);
	}

	@Override
	public void suppress()
	{

	}

	@Override
	public boolean takeControl()
	{
		return LevelSelector.getInstance().isLine() && !ComponentsRepository.evadeObstacle 
			&& Scanner.getRangeAt(0, true) < 20;
	}

}
